package com.nanhang.controller;


import com.nanhang.entity.Order;
import com.nanhang.service.IOrderService;
import com.nanhang.util.PageResult;
import com.nanhang.util.R;
import com.nanhang.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jsj
 * @since 2025-01-13
 */
@RestController
@RequestMapping("/order")
@Validated
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @PostMapping("/search/{page}/{pageSize}")
    public R search(@PathVariable("page") Integer page,
                    @PathVariable("pageSize") Integer pageSize,
                    @RequestBody(required = false) OrderVo vo){
        PageResult<Order> pr = orderService.search(page,pageSize,vo);
        return R.ok().data("pr",pr);
    }
    @PostMapping("/save")
    public R save(@Validated @RequestBody Order order){

        return orderService.save(order) ? R.ok().message("添加成功！") : R.error().message("添加失败！");
    }
    @PutMapping("/update")
    public R update(@RequestBody Order order){

        return orderService.updateById(order) ? R.ok().message("修改成功！") : R.error().message("修改失败！");
    }
    @DeleteMapping("/delete/{ids}")
    public R delete(@PathVariable("ids") String ids){
        String[] shuzu=ids.split(",");
        List<String> sids = Arrays.asList(shuzu);


        return orderService.removeByIds(sids) ? R.ok().message("删除成功！") : R.error().message("删除失败！");
    }
    @PostMapping("/delete1")
    public R delete1( @RequestBody Order order){

        return orderService.removeById(order) ? R.ok().message("删除成功！") : R.error().message("删除失败！");
    }


}
